<?php
namespace app\api\controller;
use app\common\controller\Api;
/**
 * 售后订单模块
 * User: LK
 * Date: 2021/3/31
 */
class OrderRefund extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    /**
     * 取消售后申请
     *
     * @ApiMethod   (POST)
     *
     * @param int $order_refund_id 售后订单ID
     */
    public function cancelApplyRefund(\app\common\model\order\OrderRefundModel $OrderRefundModel, \app\api\validate\OrderRefundValidate $OrderRefundValidate)
    {
        $params = $this->request->post();
        if(!$OrderRefundValidate->check($params,[],'cancelApplyRefund')){
            $this->errorReturn(40001,$params,$OrderRefundValidate->getError());
        }
        $params['user_id'] = $this->auth->id;
        $return = $OrderRefundModel->cancelApplyRefund($params);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }

    /**
     * 售后订单列表
     *
     * @ApiMethod   (POST)
     *
     * @param int $status 状态:null=全部,0=待审核,1=已审核(待发货),2=待收货,3=退款成功,4=拒绝,5=取消申请
     * @param int $page 页码
     * @param int $limit 每页条数
     * @param string $search
     */
    public function getRefundOrderPageList(\app\common\model\order\OrderRefundModel $OrderRefundModel, \app\api\validate\OrderRefundValidate $OrderRefundValidate)
    {
        $params = $this->request->post();
        if(!$OrderRefundValidate->check($params,[],'getRefundOrderPageList')){
            $this->errorReturn(40001,$params,$OrderRefundValidate->getError());
        }
        $user_id = $this->auth->id;
        $return = $OrderRefundModel->getRefundOrderPageList($params,$user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }

    /**
     * 售后订单详情
     *
     * @ApiMethod   (POST)
     *
     * @param int $order_refund_id 售后订单ID
     */
    public function refundOrderDetail(\app\common\model\order\OrderRefundModel $OrderRefundModel, \app\api\validate\OrderRefundValidate $OrderRefundValidate)
    {
        $params = $this->request->post();
        if(!$OrderRefundValidate->check($params,[],'refundOrderDetail')){
            $this->errorReturn(40001,$params,$OrderRefundValidate->getError());
        }
        $user_id = $this->auth->id;
        $return = $OrderRefundModel->refundOrderDetail($params, $user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }

    /**
     * 用户退货发货:填写快递单号和快递公司
     *
     * @ApiMethod   (POST)
     *
     * @param int $order_refund_id 售后订单ID
     * @param string $express_name 快递公司名称
     * @param string $express_no 快递单号
     */
    public function editRefundOrder(\app\common\model\order\OrderRefundModel $OrderRefundModel, \app\api\validate\OrderRefundValidate $OrderRefundValidate)
    {
        $params = $this->request->post();
        if(!$OrderRefundValidate->check($params,[],'editRefundOrder')){
            $this->errorReturn(40001,$params,$OrderRefundValidate->getError());
        }
        $user_id = $this->auth->id;
        $return = $OrderRefundModel->editRefundOrder($params, $user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }

    /**
     * 删除售后订单
     *
     * @ApiMethod   (POST)
     *
     * @param int $order_refund_id 售后订单ID
     */
    public function deleteRefund(\app\common\model\order\OrderRefundModel $OrderRefundModel, \app\api\validate\OrderRefundValidate $OrderRefundValidate)
    {
        $params = $this->request->post();
        if(!$OrderRefundValidate->check($params,[],'deleteRefund')){
            $this->errorReturn(40001,$params,$OrderRefundValidate->getError());
        }
        $user_id = $this->auth->id;
        $return = $OrderRefundModel->deleteRefund($params, $user_id);
        $this->errorReturn($return['code'],$return['data'],$return['msg']);
    }
}